#pragma once

#include "DX11Includes.h"
#include "EngineStuff.h"
#include <vector>

using namespace std;

class RenderTarget
{
public:
	RenderTarget(ID3D11RenderTargetView* view, ID3D11DepthStencilView* dsv);	
	RenderTarget(UINT size = 1);
	~RenderTarget(void);	
	void AddTarget(int num,int texW, int texH,DXGI_FORMAT format = DXGI_FORMAT_R32G32B32A32_FLOAT , UINT CPUAcess = 0,UINT samplesCount = 1, UINT samplesQuality = 0);	
	void SetDepthStencilView();
	int GetSize() {return size;}
	void SetOnDevice()
	{
		ID3D11RenderTargetView**   view = (ID3D11RenderTargetView**)malloc(sizeof(ID3D11RenderTargetView*) * size);			

		for(int i = 0 ; i < size ;i ++)
		{
			view[i] = targetsView[i];				
		}
		EngineStuff::EImediateDeviceContext->OMSetRenderTargets(size, view, depthStencilview);
	}

	void Clear( float red = 0, float green = 0, float blue = 0, float alpha = 0, bool clearDepthStencialView = false , float Depth = 1.0f )
	{
		float color[4];	
		color[0] = red;
		color[1] = green;
		color[2] = blue;
		color[3] = alpha;
		
		for(int i = 0 ; i < size ;i ++)
		{
			EngineStuff::EImediateDeviceContext->ClearRenderTargetView(targetsView[i], color);
		}
		if(clearDepthStencialView && depthStencilview)
		{
			EngineStuff::EImediateDeviceContext->ClearDepthStencilView(depthStencilview, D3D11_CLEAR_DEPTH, Depth, 0);
		}
	}

	void Clear(float* red, float* green , float* blue , float* alpha , bool clearDepthStencialView = false , float Depth = 1.0f )
	{	
		for(int i = 0 ; i < size ;i ++)
		{
			float color[4];	
			color[0] = red[i];
			color[1] = green[i];
			color[2] = blue[i];
			color[3] = alpha[i];
			EngineStuff::EImediateDeviceContext->ClearRenderTargetView(targetsView[i], color);
		}

		if(clearDepthStencialView && depthStencilview)
		{
			EngineStuff::EImediateDeviceContext->ClearDepthStencilView(depthStencilview, D3D11_CLEAR_DEPTH, Depth, 0);
		}
	}

	ID3D11ShaderResourceView* GetRenderTargetView(int num)
	{
		assert(num < size);
		return shaderResources[num];  
	}


	
private:
	UINT										size;
	vector<ID3D11Texture2D*>					textures;	
	vector<ID3D11ShaderResourceView*>			shaderResources;
	vector<ID3D11RenderTargetView*>				targetsView;
	ID3D11DepthStencilView*						depthStencilview;
};
